package popcorn.ticket.serviceimpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import popcorn.ticket.dao.GradesMapper;
import popcorn.ticket.entity.Grades;
import popcorn.ticket.entity.GradesExample;
import popcorn.ticket.service.GradesService;
import popcorn.ticket.tool.PageData;

@Service
public class GradesServiceImpl implements GradesService {
	@Autowired
	GradesMapper gradesMapper;

	@Override
	public PageData<Grades> selectGradesByLike(int page, int limit, String keywords) {
		String name = "%" + keywords + "%";
		// ue方法查询
		GradesExample ge = new GradesExample();
		PageHelper.startPage(page, limit);

		ge.createCriteria().andGradenameLike(name);
		List<Grades> data = gradesMapper.selectByExample(ge);
		// 实例化分页信息
		PageInfo<Grades> pageInfo = new PageInfo<Grades>(data);
		// 构造方法 赋值内容为 数据 总记录数 limit page
		PageData<Grades> pageData = new PageData<>();
		// 获得数据总数
		pageData.setCount((int) pageInfo.getTotal());
		pageData.setData(data);
		pageData.setLimit(limit);
		pageData.setPage(page);
		// 还有: code 从layui哪里来的
		pageData.setCode(0);
		pageData.setMsg("");

		return pageData;
	}

	@Override
	public int updateByPrimaryKeySelective(Grades grades) {
		int n = gradesMapper.updateByPrimaryKey(grades);
		return n;
	}

	@Override
	public int delGradesById(int gradeid) {
		int n = gradesMapper.deleteByPrimaryKey(gradeid);
		return n;
	}

	@Override
	public int addGrades(Grades grades) {
		int n = gradesMapper.insert(grades);
		return n;
	}

	
	@Override
	public List<Grades> getGrades() {
		GradesExample example = new GradesExample();
		example.createCriteria().andGradenameLike("%");
		List<Grades> list = gradesMapper.selectByExample(example);
		return list;
	}
}
